export const sleep = (duration: number | undefined) => new Promise((resolve) => {
  setTimeout(resolve, duration)
})

export const toast = (a: string, b: string) => {
  const c: any = document.createElement('div')
  c.style = 'position:fixed;top:40%;left:50%;z-index:999999999;border-radius:3px;opacity:0;max-width:80%;color:white;font-size:14px;box-sizing:border-box;background:rgba(0,0,0,0.76);padding:0.8em 2.618em;';
  c.innerText = a;
  document.body.appendChild(c);
  c.style.marginLeft = -(c.offsetWidth/2)+'px';
  c.style.marginTop = -c.offsetHeight / 2 + 'px'
  setTimeout(() => {
    c.style.marginLeft = -(c.offsetWidth / 2) + "px",
    c.style.marginTop = -c.offsetHeight + "px",
    c.style.transition = "all 0.3s",
    c.style.opacity = "1";
    setTimeout(() => {
      c.style.opacity = '0'
      c.style.marginTop = -c.offsetHeight / 2 + "px";
      setTimeout(function () {
        document.body.removeChild(c)
      }, 300)
    }, parseInt(b) || 1618)
  }, 0)
}